from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

from conference.models import Conference

# here we extend the basic user model to include a few more settings that we need
class UserProfile(models.Model):
	# unique identifier for User -> UserProfile
	user = models.OneToOneField(User)
	# what company they represent
	company = models.CharField(max_length=50, blank=True)
	# what conferences they're attending
	attending = models.ManyToManyField(Conference)
	# conference data
	conf = models.ManyToManyField('Profile.UserConf')

	def __str__(self):
		return "%s" % self.user

def create_user_profile(sender, instance, created, **kwargs):
	if created:
		profile, created = UserProfile.objects.get_or_create(user=instance)

User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])

# this is the per-conference user configuration model
class UserConf(models.Model):
	# which conference this model is for 
	conf = models.CharField(max_length=50)
	# are they attending?
	registered = models.BooleanField()
	# have they paid?
	paid = models.BooleanField()
	# what group are they assigned to, if any? 
	group = models.CharField(max_length=50,blank=True, null=True)
	# have they checked in?
	checked_in = models.BooleanField()
	## these two fields are for timestamps for reporting
	# what time did they check in?
	checked_in_time = models.DateField(null=True, blank=True)
	# what time did they check out?
	checked_out_time = models.DateField(null=True, blank=True)
